var pipeLineId = "";
var pipepipeSegmentId = "";




// 管线选择点击事件
function pipeSegmentClick(id) {
	// 对管段ID进行诸如
	pipeSegmentId = id;

}

function getMarkerClick() {
	// 获取一个起始点
	var startMileage = $("#startMileageId").val();
	
	// 获取一个终点
	var endMileage = $("#endMileageId").val();
	
	//将值放入隐藏域
	$("#lineHiddenId").val(pipeLineId);
	$("#segmentHiddenId").val(pipeSegmentId);
	$("#startMileHiddenId").val(startMileage);
	$("#endMileHiddenId").val(endMileage);
	
	
	var url = window.config.controlServer + "/basedata/marker/findByCondition.json";
	//清空子节点
	$("#searchBody").empty();
	
	var data = {"lineId":pipeLineId,"segmentId":pipeSegmentId,"startMileage":startMileage,"endMileage":endMileage};
	var map={"fillDiv":"#searchBody",
            "url":window.config.controlServer+"basedata/marker/findByCondition.json"};
	searchPage(map,data);
	
}


/**
 * 分页
 * @param current
 * @param pageCount
 * @param totalSize
 */
function commonPages(map){
    $("#commonsPage").createPage({
        current:parseInt(map.current),
        pageCount:parseInt(map.pageCount),
        totalSize:parseInt(map.totalSize),
        url:map.url,
        fillDiv:map.fillDiv,
        backFn:function(current,pageCount,totalSize,url,fillDiv){
            var resultMap={"current":parseInt(current),"isPage":"isPage","url":url,"fillDiv":fillDiv};
            var data={};
            searchPage(resultMap,data);
        }
    })
}

function searchPage(map,data){
	/*获取查询隐藏域的值*/
	var lineId = $("#lineHiddenId").val();
	var segmentId = $("#segmentHiddenId").val();
	var startMileage = $("#startMileHiddenId").val();
	var endMileage = $("#endMileHiddenId").val();
	
	if(lineId == "lineAll" || lineId == ""){
		lineId = null;
	}
	if(segmentId == "segmentAll" || segmentId == ""){
		segmentId = null;
	}
    var isPage=map.isPage;
    var current=1;
    if("isPage"==isPage){
        current=parseInt(map.current)
    }else{
        current=1;
    }
    var pageCount=$("#pageSelect").val();
    data.pageCount=parseInt(pageCount);
    data.current=current;
    /* */
    data.lineId = lineId;
    data.segmenetId = segmentId;
    data.startMileage = startMileage;
    data.endMileage = endMileage;
    
    $("#currentHiddenId").val(current);
    $("#pageCountHiddenId").val(pageCount);
    
    $.ajax({
        url:map.url,
        type:"post",
        dataType:"json",
        data:data,
        success:function(d){
            var p= d.main;
            var html='';
            for(var i=0;i< p.length;i++){
                html+=createProHtml(p[i],i);
            }
            
            $(map.fillDiv).html(html);
            if("isPage"==isPage){
                $("#totalSize").html(d.pageTotal);
            }else{
                $("#commonsPage").unbind();
                var resultMap={"current":1,"pageCount":pageCount,"totalSize":d.pageTotal,"url":map.url,"fillDiv":map.fillDiv};
                commonPages(resultMap);
            }
        }
    });
}


	

function createProHtml(p,i){
    var html='';
    
    var source=p.SOURCE;
  //表主键ID
	var markerid=p.MARKERID;
	
	//管线名称
	var linename=p.LINENAME;
	if(""==linename||null==linename){
		linename="-";
	}
	
	//管段名称
	var segmentName=p.SEGMENTNAME;
	if(""==segmentName||null==segmentName){
		segmentName="-";
	}
	var markerNumber=p.MARKERNUMBER;
	if(""==markerNumber||null==markerNumber){
		markerNumber="-";
	}
	
	var gpmileage=p.GPMILEAGE;
	if(""==gpmileage||null==gpmileage){
		gpmileage="-";
	}
	var markerdepth=p.MARKERDEPTH;
	if(""==markerdepth||null==markerdepth){
		markerdepth="-";
	}
	
	
	var htt="";
	if(source=="pipemarker"){
		var markergisId=obj.GISID;
		htt+=' <div class="show-ul none"> <ul class="show-list"  >'
			+'<li><span class="s1">管道名称:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">管段名称:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">标识器编号:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">出厂编号:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">绝对距离（m）:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">最近参考点:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">相对最近参考点距离（m）:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">标识类型:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">生产厂商:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">安装日期:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">施工单位:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">标识器埋深(m):</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">记录人:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">记录日期:</span> <span class="s2">-</span></li>'
			+'<li class=\"last-li\"><span class=\"s1\">备注:</span><span class=\"s2\"><textarea readonly="readonly" disabled="disabled"placeholder=\"备注描述\">-</textarea></span></li>'
			+'</ul></div></div>';
		 htt += '<input type="hidden" name="marker_data_gis_id" value = "'+ markergisId+'"/>';

	}
	else if(source=="pipewarning"){
		var warninggisId=obj.GISID;
		htt+=' <div class="show-ul none"> <ul class="show-list"  >'
			+'<li><span class="s1">管道名称:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">管段名称:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">起始位置绝对距离（m）:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">起始位置最近参考点:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">起始位置相对最近参考点距离（m）:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">终点位置绝对距离（m）:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">终点位置最近参考点:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">终点位置相对最近参考点距离（m）:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">标识类型:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">记录人:</span> <span class="s2">-</span></li>'
			+'<li><span class="s1">记录时间:</span> <span class="s2">-</span></li>'
			+'<li class=\"last-li\"><span class=\"s1\">备注:</span><span class=\"s2\"><textarea readonly="readonly" disabled="disabled"placeholder=\"备注描述\">-</textarea></span></li>'
			+'</ul></div></div>';
		htt += '<input type="hidden" name="warning_data_gis_id" value = "'+ warninggisId+'"/>';

	}
	else {
		htt="";
	}
	var sty="bg-second";
	if(i%2){
		sty="bg-white";
	}
	html+='<div class=\"info-tr\" id=\"TTTT\"><ul class=\"ul-header '+ sty +'\"><li class=\"w20\">'
	+linename+
	'</li><li class=\"w20\">'
	+segmentName+
	'</li><li class=\"w10\">'
	+markerNumber+
	'</li><li class=\"w20\">'
	+ gpmileage+
	'</li><li class=\"w20\" dateStyle=\"default\">'
	+markerdepth+
	'</li><li class=\"w10 no-right\"><em class=\"xq-icon\"  id="'+markerid+','+source+'"></em></li></ul>'
	+htt;
	
	return html;
	
}
	
function markerDetails(t,markersource){
	var strs=new Array();
	strs=markersource.split(",");
	
	var id=strs[0];
	var source=strs[1];
	var url2 = window.config.controlServer + "/basedata/marker/findById.json";
	
	$.ajax({
		type : "post",
		data:{id : id,source : source},
		url : url2,
		dataType : "json",
		success : function(data) {
			console.log(data);
			if(null!=data||""!=data){
				var obj = data.main[0];
				{
					
						if(source=="pipemarker"){
							
							//管道名称
							var LINENAME=obj.LINENAME;
							if(null==LINENAME||""==LINENAME){
								LINENAME="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(0).find('span').eq(1).html(LINENAME);
							//管道名称
							var SEGMENTNAME=obj.SEGMENTNAME;
							if(null==SEGMENTNAME||""==SEGMENTNAME){
								SEGMENTNAME="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(1).find('span').eq(1).html(SEGMENTNAME);
							//标识器编号	
							var MARKERNUMBER=obj.MARKERNUMBER;
							if(null==MARKERNUMBER||""==MARKERNUMBER){
								MARKERNUMBER="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(2).find('span').eq(1).html(MARKERNUMBER);
							
							//出厂编号	
							var MANUFACTUREDNUM=obj.MANUFACTUREDNUM;
							if(null==MANUFACTUREDNUM||""==MANUFACTUREDNUM){
								MANUFACTUREDNUM="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(3).find('span').eq(1).html(MANUFACTUREDNUM);
							
							//"绝对距离（m）"
							var GPMILEAGE=obj.GPMILEAGE;
							if(null==GPMILEAGE||""==GPMILEAGE){
								GPMILEAGE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(4).find('span').eq(1).html(GPMILEAGE);
							
							//最近参考点
							var GPREFERENCE=obj.GPREFERENCE;
							if(null==GPREFERENCE||""==GPREFERENCE){
								GPREFERENCE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(5).find('span').eq(1).html(GPREFERENCE);
							
							//"相对最近参考点距离（m）"
							var GPREFERENCEDISTANCE=obj.GPREFERENCEDISTANCE;
							if(null==GPREFERENCEDISTANCE||""==GPREFERENCEDISTANCE){
								GPREFERENCEDISTANCE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(6).find('span').eq(1).html(GPREFERENCEDISTANCE);
							
							//标识类型	
							var MARKER_TYPE=obj.MARKER_TYPE;
							if(null==MARKER_TYPE||""==MARKER_TYPE){
								MARKER_TYPE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(7).find('span').eq(1).html(MARKER_TYPE);
							
							//生产厂商	
							var MANUFACTURER=obj.MANUFACTURER;
							if(null==MANUFACTURER||""==MANUFACTURER){
								MANUFACTURER="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(8).find('span').eq(1).html(MANUFACTURER);
							
							//安装日期	
							var INSTALLDATE=obj.INSTALLDATE;
							if(null==INSTALLDATE||""==INSTALLDATE){
								INSTALLDATE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(9).find('span').eq(1).html(INSTALLDATE);
							
							//施工单位	
							var ASSEMBLYCOMPANY=obj.ASSEMBLYCOMPANY;
							if(null==ASSEMBLYCOMPANY||""==ASSEMBLYCOMPANY){
								ASSEMBLYCOMPANY="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(10).find('span').eq(1).html(ASSEMBLYCOMPANY);
							
							//标识器埋深(m)	
							var MARKERDEPTH=obj.MARKERDEPTH;
							if(null==MARKERDEPTH||""==MARKERDEPTH){
								MARKERDEPTH="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(11).find('span').eq(1).html(MARKERDEPTH);
							
							//记录人	
							var RECORDER=obj.RECORDER;
							if(null==RECORDER||""==RECORDER){
								RECORDER="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(12).find('span').eq(1).html(RECORDER);
							
							//记录日期	
							var RECORDTIME=obj.RECORDTIME;
							if(null==RECORDTIME||""==RECORDTIME){
								RECORDTIME="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(13).find('span').eq(1).html(RECORDTIME);
							
							
							//备注
							var CREATEREMARK=obj.CREATEREMARK;
							if(null==CREATEREMARK||""==CREATEREMARK){
								CREATEREMARK="-";
							}
							t.parents('.ul-header').next().find('.show-list li').eq(14).find('span').eq(1).find("textarea").eq(0).html(CREATEREMARK);
							
							
						}else if(source=="pipewarning"){
							
							
							//*管道名称	
							var LINENAME=obj.LINENAME;
							if(null==LINENAME||""==LINENAME){
								LINENAME="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(0).find('span').eq(1).html(LINENAME);
							//管段名称	
							var SEGMENTNAME=obj.SEGMENTNAME;
							if(null==SEGMENTNAME||""==SEGMENTNAME){
								SEGMENTNAME="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(1).find('span').eq(1).html(SEGMENTNAME);
							//起始位置绝对距离（m）:
							var STARTMILEAGE=obj.STARTMILEAGE;
							if(null==STARTMILEAGE||""==STARTMILEAGE){
								STARTMILEAGE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(2).find('span').eq(1).html(STARTMILEAGE);
							//起始位置最近参考点:
							var STARTREFERENCE=obj.STARTREFERENCE;
							if(null==STARTREFERENCE||""==STARTREFERENCE){
								STARTREFERENCE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(3).find('span').eq(1).html(STARTREFERENCE);
							//起始位置相对最近参考点距离（m）
							var STARTREFERENCEDISTANCE=obj.STARTREFERENCEDISTANCE;
							if(null==STARTREFERENCEDISTANCE||""==STARTREFERENCEDISTANCE){
								STARTREFERENCEDISTANCE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(4).find('span').eq(1).html(STARTREFERENCEDISTANCE);
							//终点位置绝对距离（m）:
							var ENDMILEAGE=obj.ENDMILEAGE;
							if(null==ENDMILEAGE||""==ENDMILEAGE){
								ENDMILEAGE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(5).find('span').eq(1).html(ENDMILEAGE);
							//终点位置最近参考点:
							var ENDREFERENCE=obj.ENDREFERENCE;
							if(null==ENDREFERENCE||""==ENDREFERENCE){
								ENDREFERENCE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(6).find('span').eq(1).html(ENDREFERENCE);
							//终点位置相对最近参考点距离（m）
							var ENDREFERENCEDISTANCE=obj.ENDREFERENCEDISTANCE;
							if(null==ENDREFERENCEDISTANCE||""==ENDREFERENCEDISTANCE){
								ENDREFERENCEDISTANCE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(7).find('span').eq(1).html(ENDREFERENCEDISTANCE);
							//标识类型	
							var WARNINGMARKERTYPE=obj.WARNINGMARKERTYPE;
							if(null==WARNINGMARKERTYPE||""==WARNINGMARKERTYPE){
								WARNINGMARKERTYPE="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(8).find('span').eq(1).html(WARNINGMARKERTYPE);
							//记录人	
							var WARNINGRECORDER=obj.WARNINGRECORDER;
							if(null==WARNINGRECORDER||""==WARNINGRECORDER){
								WARNINGRECORDER="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(9).find('span').eq(1).html(WARNINGRECORDER);
							//记录时间	
							var WARNINGRECORDTIME=obj.WARNINGRECORDTIME;
							if(null==WARNINGRECORDTIME||""==WARNINGRECORDTIME){
								WARNINGRECORDTIME="-";
							}
							
							t.parents('.ul-header').next().find('.show-list li').eq(10).find('span').eq(1).html(WARNINGRECORDTIME);
							//备注
							var CREATEREMARK=obj.CREATEREMARK;
							if(null==CREATEREMARK||""==CREATEREMARK){
								CREATEREMARK="-";
							}
							t.parents('.ul-header').next().find('.show-list li').eq(11).find('span').eq(1).find("textarea").eq(0).html(CREATEREMARK);
							
							
						}
						
					}
				}
			}
			
			
		});
	
	
	
}
